home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / terminal / vltj5867.lha / VLT / rexx / VLTPhoneModify.rexx < prev    next >
Encoding:
OS/2 REXX Batch file  |  1994-03-27  |  4.9 KB  |  210 lines

  1. /** VLTPhoneModify.rexx
  2. *
  3. *   Create or Modify an entry in the VLT PhoneBook
  4. *
  5. *   By W.G.J. Langeveld, February 1992.
  6. *
  7. **/
  8. parse arg action
  9. /*
  10. *   Add libraries if necessary
  11. */
  12. if show("l", "rexxarplib.library") = 0 then do
  13.    check = addlib('rexxsupport.library', 0, -30, 0)
  14.    check = addlib('rexxarplib.library',  0, -30, 0)
  15. end
  16. /*
  17. *   Get VLT port, screen name and size
  18. */
  19. vltport = address()
  20. cols = ScreenCols(vltport)
  21. if cols == -1 then do
  22.    vltscreen = ""
  23.    cols = ScreenCols()
  24.    rows = ScreenRows()
  25. end
  26. else do
  27.    vltscreen = vltport
  28.    rows = ScreenRows(vltscreen)
  29. end
  30. /*
  31. *   Check if we're set up right
  32. */
  33. call pragma('W','NULL')
  34.  
  35. if ~exists("VLTPhoneBook:") then do
  36.    "@VLTPhoneSetup.rexx"
  37.    exit
  38. end
  39. /*
  40. *   If this is a modify, which entry?
  41. */
  42. changes. = ""
  43. if upper(action) = "MODIFY" then do
  44.    filename = GetFile(80, 50, "VLTPhoneBook:",, "Entry Name:", vltscreen)
  45.    if filename == "" then exit
  46. /*
  47. *   Open it
  48. */
  49.    if open(input, filename, "r") = 0 then do
  50.       "message (Couldn't read file); delay 1.5; message"
  51.       exit
  52.    end
  53. /*
  54. *   Read it.
  55. */
  56.    do i = 1 to 10
  57.       changes.i = readln(input)
  58.    end
  59.    call close(input)
  60. end
  61. else do
  62.    changes.4 = "ATDT"
  63.    changes.5 = "ATZ"
  64.    changes.6 = "9600"
  65.    changes.7 = "8N1"
  66. end
  67. /*
  68. *   Make a new port name
  69. */
  70. do i = 1
  71.    hostname = VLTPHONEMOD || i
  72.    if showlist('p', hostname) = 0 then leave
  73. end
  74. portname = hostname || "PORT"
  75. /*
  76. *   Set up a host.
  77. */
  78. address AREXX "'x = CreateHost("hostname", "portname" , "vltscreen")'"
  79. /*
  80. *   Wait until it is ready.
  81. */
  82. do i = 1
  83.    if showlist('p', hostname) ~= 0 then leave
  84.    call delay 30
  85. end
  86.  
  87. call SetReqColor(hostname, BACKGROUNDPEN, 0)
  88. /*
  89. *   Open the port that messages will come to
  90. */
  91. mp = openport(portname)
  92. /*
  93. *   Open the window
  94. */
  95. idcmp = 'CLOSEWINDOW+GADGETUP'
  96. flags = 'WINDOWCLOSE+WINDOWDRAG+WINDOWDEPTH+ACTIVATE'
  97. title = "VLTPhoneBook "action" Entry"
  98. call OpenWindow(hostname, cols - 600, rows - 200, 450, 200, idcmp,     ,
  99.                 flags, title)
  100. /*
  101. *   Add the gadgets
  102. */
  103. prompts =              "\\Name:\\Address:\\City etc.:"
  104. prompts = prompts || "\\Phone Number:               Modem Init:"
  105. prompts = prompts || "\\Modem Speed:                Parity:"
  106. prompts = prompts || "\\Predial Cmds:\\Postdial Cmds:\\Notes:"
  107.  
  108. call WindowText(hostname, prompts)
  109.  
  110. call AddGadget(hostname, 140,  36,  1, changes.1,  "%d%1%g", 290, RIDGEBORDER)
  111. call AddGadget(hostname, 140,  54,  2, changes.2,  "%d%1%g", 290, RIDGEBORDER)
  112. call AddGadget(hostname, 140,  72,  3, changes.3,  "%d%1%g", 290, RIDGEBORDER)
  113. call AddGadget(hostname, 140,  90,  4, changes.4,  "%d%1%g",  96, RIDGEBORDER)
  114. call AddGadget(hostname, 342,  90,  5, changes.5,  "%d%1%g",  88, RIDGEBORDER)
  115. call AddGadget(hostname, 140, 108,  6, changes.6,  "%d%1%g",  96, RIDGEBORDER)
  116. call AddGadget(hostname, 342, 108,  7, changes.7,  "%d%1%g",  88, RIDGEBORDER)
  117. call AddGadget(hostname, 140, 126,  8, changes.8,  "%d%1%g", 290, RIDGEBORDER)
  118. call AddGadget(hostname, 140, 144,  9, changes.9,  "%d%1%g", 290, RIDGEBORDER)
  119. call AddGadget(hostname, 140, 162, 10, changes.10, "%d%1%g", 290, RIDGEBORDER)
  120.  
  121. call AddGadget(hostname,  22, 183, 11, "  Okay  ", "OKAY")
  122. call AddGadget(hostname, 362, 183, 12, " Cancel ", "CANCEL")
  123.  
  124. call ActivateGadget(hostname, 1)
  125. /*
  126. *   Main event loop
  127. */
  128. quitflag  = 0
  129. finalpass = 0
  130.  
  131. do forever
  132.    if quitflag = 1 then leave
  133.    t = waitpkt(portname)
  134.    do forever
  135.       p = getpkt(portname)
  136.       if c2d(p) = 0 then leave
  137.  
  138.       cmd = getarg(p)
  139.       if datatype(cmd, 'W') ~= 0 then string = getarg(p, 1)
  140.  
  141.       t = reply(p, 0)
  142. /*
  143. *   See what we got
  144. */
  145.       if finalpass = 0 then do
  146.          if cmd = CLOSEWINDOW then do
  147.             call CloseWindow(hostname)
  148.             quitflag = 1
  149.          end
  150.          else if cmd = OKAY then do
  151. /*
  152. *   Send read requests for all gadgets and set up for second pass
  153. */
  154.             do i = 1 to 10
  155.                call ReadGadget(hostname, i)
  156.             end
  157.             finalpass = 1
  158.          end
  159.          else if cmd = CANCEL then do
  160.             call CloseWindow(hostname)
  161.             quitflag = 1
  162.          end
  163.          else do
  164.             if datatype(cmd, 'W') ~= 0 then do
  165.                cmd = cmd + 1
  166.                if cmd > 10 then cmd = 1
  167.                call ActivateGadget(hostname, cmd)
  168.             end
  169.          end
  170.       end
  171.       else do
  172. /*
  173. *   Second pass. We're reading the gadgets
  174. */
  175.          if datatype(cmd, 'W') ~= 0 then do
  176.             changes.cmd = string
  177.             if cmd = 10 then do
  178.                call CloseWindow(hostname)
  179.                quitflag = 1
  180.             end
  181.          end
  182.       end
  183.    end
  184. end
  185.  
  186. /*
  187. *   Write out the modified data
  188. */
  189. if finalpass = 1 then do
  190.    if upper(action) ~= "MODIFY" then do
  191.       filename = GetFile(80, 50, "VLTPhoneBook:",, "New Entry Name:",    ,
  192.                          vltscreen,,,"SAVE")
  193.       if filename == "" then exit
  194.    end
  195.  
  196.    if open(output, filename, "w") = 0 then do
  197.       "message (Couldn't write file); delay 1.5; message"
  198.       exit
  199.    end
  200.  
  201.    do i = 1 to 10
  202.       writeln(output, changes.i)
  203.    end
  204.  
  205.    call close(output)
  206. end
  207.  
  208. exit
  209.  
  210.